package com.mcy.springbatch.writer;

import com.mcy.springbatch.entity.SysUser;
import org.springframework.batch.item.xml.StaxEventItemWriter;
import org.springframework.core.io.FileSystemResource;
import org.springframework.oxm.xstream.XStreamMarshaller;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

/**
 * 利用StaxEventItemWriter把对象转xml写出到xml文件
 * @author : Create By mcy
 * @date : 2019/8/25 16:15:46
 */
@Component
public class SysUserStaxEventItemWriter extends StaxEventItemWriter<SysUser> {

    @PostConstruct
    public void init(){
        XStreamMarshaller marshaller = new XStreamMarshaller();
        Map<String, Class> map = new HashMap<>();
        map.put("user",SysUser.class);
        marshaller.setAliases(map);
        setRootTagName("users");
        setMarshaller(marshaller);
        setResource(new FileSystemResource("/Users/calon/Desktop/userdata.xml"));
    }

}
